package dgut.party.business.entity.publication;

import com.fasterxml.jackson.annotation.JsonFormat;
import dgut.party.business.common.enumeration.Priority;
import dgut.party.business.entity.base.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@SuperBuilder
@NoArgsConstructor
@ToString
public class Publication extends BaseEntity implements Serializable {
  private static final long serialVersionUID = 111709857261161447L;


  @Enumerated(EnumType.ORDINAL)
  protected Priority priority;

  protected Boolean disabled;

  @Column(length = 50)
  protected String title;

  @Column(name = "dtype", insertable = false, updatable = false)
  protected String type;

  protected String summary;

  /**
   * 摘要
   * Clob（Character Large Ojects）类型是长字符串类型Blob（Binary Large Objects）类型是字节类型
   *
   * @Lob 持久化为Blob或者Clob类型, 根据get方法的返回值不同, 自动进行Clob和Blob的转换。
   * @author: Mercy Wu(a3049)
   * 2018年2月11日 下午11:47:09
   */
  @Lob
  protected String content;

  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  protected Date endTime;

  @PrePersist
  protected void beforePersist() {
    super.beforePersist();
    if (this.disabled == null) this.disabled = false;
    if (this.priority == null) this.priority = Priority.NORMAL;
  }


  public String getEntityClassName() {
    return this.getClass().getSimpleName();
  }
}
